using System;
using System.Windows.Forms;
using Microsoft.Extensions.DependencyInjection;
using WinformTemplete.Common;
using WinformTemplete.Models;
using WinformTemplete.Repositories;

using SqlSugar;
using WinformTemplete.Modules.Blog.Services;
using WinformTemplete.Modules.Blog.Repositories;

namespace WinformTemplete
{
    internal static class Program
    {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // 配置依赖注入
            var services = new ServiceCollection();

            // 注册数据库连接
            services.AddSingleton<SqlSugarClient>(provider => DatabaseManager.GetInstance());

            // 注册仓储
            services.AddTransient<IBlogRepository, BlogRepository>();

            // 注册服务
            services.AddTransient<IBlogService, BlogService>();

            // 注册窗体
            services.AddTransient<Modules.Blog.BlogForm>();
            services.AddTransient<MainForm>();

            // 构建服务提供者
            var serviceProvider = services.BuildServiceProvider();

            // 运行应用程序
            Application.Run(serviceProvider.GetRequiredService<MainForm>());
        }
    }
}